// 8_3 Class template.cpp : Defines the entry point for the console application.
//编写一个类模板，完成对不同数据类型的数组的排序（小到大）操作。如下是输入的数据
//int array[5]={3,6,2,1,4};
//double array[5]={3.1,1.2,4.5,1.1,0.2};
#include "stdafx.h"
#include<iostream>
using namespace std;
const int n = 5;//此处定义数组长度
class value
{
public:
	double maximum(double *a);
	double minimum(double *a);
	double average(double *a);
	void Integer(int *a);
	void dou(double *a);
	void sin(void);
};
double value::maximum(double *a)
{
	double x=*a;
	for(int i=0;i<n;i++){
		if(*a>x){
			x=*a;
		}
			a++;
	}
	return x;
}
double value::minimum(double *a)
{
	double y=*a;
	for(int j=0;j<n;j++){
		if(*a<y){
			y=*a;
		}
		a++;
	}
	return y;
}
double value::average(double *a)
{
	double z=0;
	for(int k=0;k<n;k++){
		z=z+*a;
		a++;
	}
	return (z/n);
}
void getin(double a[])
{
	cout<<"please input a array:"<<endl;
	for(int m=0;m<n;m++){
		cin>>a[m];
	}
}
void value::Integer(int *a)
{
	int m;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(*(a+j)>*(a+i)){
				m=*(a+i);
				*(a+i)=*(a+j);
				*(a+j)=m;
			}
		}
	}
}
void value::dou(double *a)
{
	double m;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(*(a+j)>*(a+i)){
				m=*(a+i);
				*(a+i)=*(a+j);
				*(a+j)=m;
			}
		}
	}
}
void value::sin(void)
{
	cout<<"Sorted array:";
}
void main()
{
	double a[n];
	getin(a);
	value value1;
	cout<<"average: "<<value1.average(a)<<endl<<"minimum: "<<value1.minimum(a)<<endl<<"maximum: "<<value1.maximum(a)<<endl;
	value1.sin();
	value1.dou(a);
	for(int i=0;i<n;i++){
		cout<<a[i]<<" ";
	}//texting satistic 1 2 54 51 21 51 2 15 15 45 25 13 15 1 2 1.1 2.2 3.3 -3.3 -2
	cout<<endl;
}
